<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function get(url) {
        return fetch(url, {
          method: "get", // 请求的方式
        });
      }

      function post(url, data) {
        return fetch(url, {
          method: "post",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify(data),
        });
      }

      post("http://localhost/test", { username: "admin", password: "123" })
        .then((response) => {
          response.json().then((data) => {
            console.log(data);
          });
        })

        .catch((reason) => {
          console.log(reason);
          console.log("请求失败");
        });
    </script>
  </body>
</html>
